﻿@model DeleteAccountViewModel
@{
    var isOrganization = Model.User is Organization;
    var hasSingleOwnerMessage = isOrganization ? "You must transfer ownership of this package before you can delete your organization." : "After account deletion, this package will not have any owners.";
    var hasMultipleOwnersMessage = isOrganization ? "You do not need to transfer ownership of this package before you can delete your organization." : "After account deletion, this package will still have at least one owner.";
}

@if (!Model.Packages.Any())
{
    <p>This account owns no packages.</p>

    return;
}

<div class="row user-package-list align-left">
    <div class="col-md-12 align-left ">
        <div class="panel-collapse collapse in" id="packages-Packages" aria-expanded="true">
            <div class="list-packages" role="list">
                <table class="table align-left">
                    <thead>
                        <tr class="manage-package-headings">
                            <th class="hidden-xs"></th>
                            <th class="hidden-xs"></th>
                            <th>Package ID</th>
                            <th>Owners</th>
                            <th>Downloads</th>
                            <th>Latest Version</th>
                            <th class="hidden-xs"></th>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach (var package in @Model.Packages)
                    {
                        <tr class="manage-package-listing">
                            <td class="align-middle ">
                                @if (package.WillBeOrphaned)
                                {
                                    <i class="ms-Icon ms-Icon--StatusErrorFull red-check" title="@hasSingleOwnerMessage"></i>
                                }
                                else
                                {
                                    <i class="ms-Icon ms-Icon--CompletedSolid green-check" title="@hasMultipleOwnersMessage"></i>
                                }
                            </td>
                            <td class="align-middle hidden-xs">
                                <img class="package-icon img-responsive" aria-hidden="true" alt="Package Icon"
                                     src="@(PackageHelper.ShouldRenderUrl(package.IconUrl) ? package.IconUrl : Url.Absolute("~/Content/gallery/img/default-package-icon.svg"))"
                                     @ViewHelpers.ImageFallback(Url.Absolute("~/Content/gallery/img/default-package-icon-256x256.png")) />
                            </td>
                            <td class="align-middle package-id"><a href="@Url.Package(package.Id)">@Html.BreakWord(package.Id.Abbreviate(40))</a></td>
                            <td class="align-middle">
                                @{ 
                                    var index = -1;
                                    var ownerCount = package.Owners.Count;
                                    foreach (var owner in package.Owners)
                                    {
                                        index++;
                                        if (index < 2)
                                        {
                                            @ViewHelpers.UserLinkWithIcon(Url, owner);
                                            if (index < ownerCount - 1)
                                            {
                                                <text>,&nbsp;</text>
                                            }
                                        }
                                        else if (index == 2)
                                        {
                                            if (ownerCount > 2)
                                            {
                                                <span class="ms-noWrap">+ @(ownerCount - 1)</span>
                                            }
                                            break;
                                        }
                                    }
                                }
                            </td>
                            <td class="align-middle text-nowrap">@package.TotalDownloadCount.ToNuGetNumberString()</td>
                            <td class="align-middle text-nowrap">@package.FullVersion.Abbreviate(15)</td>
                            <td class="text-right align-middle package-controls">
                                <a href="@Url.ManagePackage(package)" class="btn" title="Manage" aria-label="Manage Package @package.Id">
                                    <i class="ms-Icon ms-Icon--People" aria-hidden="true"></i>
                                </a>
                            </td>
                        </tr>
                    }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>